package com.voltmaon.shortlink.vo;

import java.io.Serializable;
import java.util.Objects;

import org.joda.time.DateTime;

import cn.hutool.core.util.BooleanUtil;
import cn.hutool.core.util.RandomUtil;

/**
 * @author lfj
 */
@lombok.Getter
@lombok.Setter
@lombok.NoArgsConstructor
public class ShortLinkVO implements Serializable {
	private static final long serialVersionUID = 1L;
	/**
	 * 密码保护
	 */
	private Boolean isAuth;
	/**
	 * 短链接有效天数
	 */
	private Integer deadline;
	/**
	 * 完整链接
	 */
	private String fullLink;
	/**
	 * 过期失效跳转链接
	 */
	private String expiresLink;
	/**
	 * 认证失败跳转链接
	 */
	private String authFaildLink;

	public DateTime getEffectiveDate() {
		if(Objects.isNull(deadline) || deadline < 1) {
			return null;
		}
		return DateTime.now()
			.plusDays(deadline);
	}

	public String getAuthCode() {
		if(BooleanUtil.isTrue(isAuth)) {
			return RandomUtil.randomNumbers(4);
		}
		return null;
	}
}